package com.yj.generator;



import com.yj.generator.constants.ConfigConstant;
import com.yj.generator.core.GenerateExecutor;
import com.yj.generator.core.SqlExecutor;
import com.yj.generator.entity.GenerateOut;
import com.yj.generator.utils.PropertiesUtil;

import java.util.Arrays;

/**
 * @author DengLin
 * @title 启动
 * @date 2024/07/04
 */
public class BaseApplication {
    public static void run() {
        SqlExecutor sqlExecutor = SqlExecutor.builder()
                .url(PropertiesUtil.getProperty(ConfigConstant.DATASOURCE_URL))
                .username(PropertiesUtil.getProperty(ConfigConstant.DATASOURCE_USERNAME))
                .password(PropertiesUtil.getProperty(ConfigConstant.DATASOURCE_PASSWORD))
                .driver(PropertiesUtil.getProperty(ConfigConstant.DATASOURCE_DRIVER))
                .build();

        GenerateExecutor generateExecutor = new GenerateExecutor(sqlExecutor);

        GenerateOut generateOut = new GenerateOut();
        generateOut.setAuthor(PropertiesUtil.getProperty(ConfigConstant.GENERATE_OUT_AUTHOR));
        generateOut.setOutPath(PropertiesUtil.getProperty(ConfigConstant.GENERATE_OUT_PATH));
        generateOut.setOutPackage(PropertiesUtil.getProperty(ConfigConstant.GENERATE_OUT_PACKAGE));
        generateOut.setOutEntity(PropertiesUtil.getProperty(ConfigConstant.GENERATE_OUT_ENTITY_MODULE));
        generateOut.setOutMapper(PropertiesUtil.getProperty(ConfigConstant.GENERATE_OUT_MAPPER_MODULE));
        generateOut.setOutController(PropertiesUtil.getProperty(ConfigConstant.GENERATE_OUT_CONTROLLER));

        String[] tableNames = PropertiesUtil.getProperty(ConfigConstant.GENERATE_TABLES).split(",|，");

        generateExecutor.execute(generateOut, Arrays.asList(tableNames));
    }

    public static void main(String[] args) {
        BaseApplication.run();
    }
}
